package vesion2.object;

import com.fasterxml.jackson.annotation.JsonIgnore;
import vesion2.object.special.Topology;

import java.awt.*;

public class Rectangle extends GameObject{

    protected Point left_up;
    @JsonIgnore
    protected Point right_down;

    protected int width,height;

    /**
     *
     * @param left_up 左上角顶点
     * @param width  宽
     * @param height 高
     */
    public Rectangle(Point left_up,int width,int height){
        this(left_up,width,height,null,null);
    }

    public Rectangle(){this(new Point(),0,0);}

    public Rectangle(Rectangle rectangle){
        this(rectangle.getLeft_up(), rectangle.getWidth(), rectangle.getHeight());
    }

    public void setRight_down(Point right_down) {
        this.right_down = right_down;
    }

    public Rectangle(Point left_up, Point right_down){
        super(null,null);
        this.left_up=left_up;
        this.right_down=right_down;
        width=right_down.getX()- left_up.getX();
        height=right_down.getY()-left_up.getY();
    }

    public Rectangle(Point left_up,int width,int height,Color backColor,Image image)
    {
        super(backColor,image);
        this.left_up=left_up;
        this.right_down=new Point(left_up.getX()+width, left_up.getY()+height);
        this.height=height;
        this.width=width;
    }

    public Point getLeft_up() {
        return left_up;
    }

    public void setLeft_up(Point left_up) {
        this.left_up = left_up;
        right_down.setX(left_up.getX()+width);
        right_down.setY(left_up.getY()+height);
    }

    public Point getRight_down() {
        right_down.setX(left_up.getX()+width);
        right_down.setY(left_up.getY()+height);
        return right_down;
    }


    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
        right_down.setX(left_up.getX()+width);
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
        right_down.setY(left_up.getY()+height);
    }
    @Override
    public void draw(Graphics g) {
            g.setColor(backColor);
            g.fill3DRect(left_up.getX(), left_up.getY(), getWidth(), getHeight(), true);
    }

    @Override
    public boolean isIntersect(GameObject object) {
       return Topology.isIntersect(this,object);
    }

    @Override
    public String toString() {
        return "Rectangle{" +
                "isAlive=" + isAlive +
                ", backColor=" + backColor +
                ", left_up=" + left_up +
                ", right_down=" + right_down +
                ", width=" + width +
                ", height=" + height +
                '}';
    }
}
